package com.hdoit.ares.logical.insu.dao.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import com.hdoit.ares.logical.insu.dao.IFanhuaAccidentDao;
import com.hdoit.ares.logical.insu.model.FanhuaAccident;
import com.hdoit.ares.logical.viewmodel.insu.FanhuaAccidentSearch;
import com.tennetcn.common.dao.base.IFinderExpression;
import com.tennetcn.common.dao.base.impl.SuperDao;
import com.tennetcn.common.enums.OrderEnum;
import com.tennetcn.common.message.PagerModel;
import com.tennetcn.common.utils.FinderExpressionFactory;
/**
 * @author      caochengmeng
 * @email       
 * @createtime  2017年12月10日 23:03:25
 * @comment
 */
@Component
public class FanhuaAccidentDaoImpl extends SuperDao<FanhuaAccident> implements IFanhuaAccidentDao{
	
	@Override
	public List<FanhuaAccident> queryAllAccidentInsurance(String customerId) {
		IFinderExpression finderExpression=FinderExpressionFactory.createExpression();
		finderExpression.select("*")
						.from(FanhuaAccident.class)
						.andEq("customerId",customerId)
						.addOrder("submitTime", OrderEnum.desc);
	    return queryList(finderExpression);
	}

	@Override
	public List<FanhuaAccident> queryNoAccidentInsurance(String customerId) {
		IFinderExpression finderExpression=FinderExpressionFactory.createExpression();
		finderExpression.select("*")
						.from(FanhuaAccident.class)
						.andEq("customerId",customerId)
						.andEq("appStatus","1")
						.andWhere("TIMESTAMPDIFF(SECOND,endTime,NOW())>=0")
						.addOrder("submitTime", OrderEnum.desc);
	    return queryList(finderExpression);
	}

	@Override
	public List<FanhuaAccident> queryYesAccidentInsurance(String customerId) {
		IFinderExpression finderExpression=FinderExpressionFactory.createExpression();
		finderExpression.select("*")
						.from(FanhuaAccident.class)
						.andEq("customerId",customerId)
						.andEq("appStatus","1")
						.andWhere("NOW() BETWEEN startTime and endTime")
						.addOrder("submitTime", OrderEnum.desc);
	    return queryList(finderExpression);
	}

	@Override
	public List<FanhuaAccident> queryReadyAccidentInsurance(String customerId) {
		IFinderExpression finderExpression=FinderExpressionFactory.createExpression();
		finderExpression.select("*")
						.from(FanhuaAccident.class)
						.andEq("customerId",customerId)
						.andEq("appStatus","1")
						.andWhere("TIMESTAMPDIFF(SECOND,startTime,NOW())<=0")
						.addOrder("submitTime", OrderEnum.desc);
	    return queryList(finderExpression);
	}

	@Override
	public List<FanhuaAccident> queryList(FanhuaAccidentSearch accidentInsurance, PagerModel pagerModel) {
		IFinderExpression finderExpression=FinderExpressionFactory.createExpression();
		finderExpression.select("*")
						.from(FanhuaAccident.class)
						.addOrder("submitTime", OrderEnum.desc);
		if(pagerModel == null){
			return queryList(finderExpression, accidentInsurance);
		}		
		return queryList(finderExpression, accidentInsurance,pagerModel);
	}

	@Override
	public List<FanhuaAccident> queryFailAccidentInsurance(String customerId) {
		IFinderExpression finderExpression=FinderExpressionFactory.createExpression();
		finderExpression.select("*")
						.from(FanhuaAccident.class)
						.andEq("customerId",customerId)
						.andEq("appStatus","0")
						.addOrder("submitTime", OrderEnum.desc);
	    return queryList(finderExpression);
	}

	@Override
	public FanhuaAccident queryModelByPolicyNo(String policyNo) {
		IFinderExpression finderExpression=FinderExpressionFactory.createExpression();
		finderExpression.select("*")
						.from(FanhuaAccident.class)
						.andEq("policyNo",policyNo);
	    return queryModel(finderExpression);
	}
	
	
}